package com.wanxi.control.servlet;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.control.model.UserModel;
import com.wanxi.control.service.impl.UserServiceImpl;
import com.wanxi.control.service.IuserService;
import com.wanxi.control.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register")
public class UserAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        JSONObject jsonObject = new JSONObject();

        jsonObject.put("result",1);
        UserModel userModel = new UserModel();
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String mobile = req.getParameter("mobile");
        String weight = req.getParameter("weight");
        String email = req.getParameter("email");
        String gender = req.getParameter("gender");
        String hobby = req.getParameter("hobby");
        String birthday = req.getParameter("birthday");
        userModel.setUserName(username);
        userModel.setPassWord(password);
        userModel.setMobile(mobile);
        userModel.setWeight(Tool.StringToFloat(weight));
        userModel.setEmail(email);
        userModel.setGender(gender);
        userModel.setHobby(hobby);
        userModel.setBirthDay(birthday);
        IuserService iuserService = new UserServiceImpl();
        String result = iuserService.add(userModel);
        resp.getWriter().print(jsonObject);
    }
}
